<?php

/*

 This file is part of Gul 2 project.

 Gul project is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Gul project distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Gul project; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/


function GulWindow()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 if(!$Xo[HIDECHROME]) $window = new GtkWindow();
 else $window = new GtkWindow(1);
 $Xlast[currentwin]=$window;

 if($Xo[TITLE]) $window->set_title(utf8_decode($Xo[TITLE]));
 
 if(isset($Xo[SCREENX])||isset($Xo[SCREENY]))
 {
   if(!isset($Xo[SCREENX])) $Xo[SCREENX]=-1;
   if(!isset($Xo[SCREENY])) $Xo[SCREENY]=-1;
   $window->move($Xo[SCREENX],$Xo[SCREENY]);
 }
 
 $Xo[SIZEMODE]=strtolower($Xo[SIZEMODE]);
 if($Xo[SIZEMODE]=='maximized') $window->maximize();

 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,0),$Xo[ORIENT]);

 if($Xo[ORIENT])
 {
  $Xo[ALIGN]=strtolower($Xo[ALIGN]);
  if($Xo[ALIGN]=='start'||$Xo[ALIGN]=='center'||$Xo[ALIGN]=='end') $flex2=0;
  else $flex2=1;
  if($Xo[ALIGN]=='left'||$Xo[ALIGN]=='right') $flex=0;
  else $flex=1;

  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0),$Xo[ALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkHBox();
 }
 else
 {
  if($Xo[ALIGN]) $flex=0; else $flex=1;
  if($Xo[VALIGN]) $flex2=0; else $flex2=1;

  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0),$Xo[ALIGN]);
  $Xo[VALIGN]=GulOptions(array('top','middle','bottom'),array(0,0.5,1,0),$Xo[VALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkVBox();
 }
 //$box->set_spacing(5);

 $Xo[OVERFLOW]=GulOptions(array('auto','scroll'),array(1,2,0),$Xo[OVERFLOW]);
 if($Xo[OVERFLOW])
 {
  $scrwnd=new GtkScrolledWindow();
  if($Xo[OVERFLOW]==1) $scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  if($Xo[OVERFLOW]==2) $scrwnd->set_policy(Gtk::POLICY_ALWAYS,Gtk::POLICY_ALWAYS);

  $window->add($scrwnd);
  $scrwnd->add_with_viewport($align);
  $scrwnd->child->set_shadow_type(0);
 }
 else $window->add($align);

 GulStyle('padding:5px;'.$Xlast[$Yn][STYLE],$window,$window,'','','',$align);

 if(isset($Xo[CONTEXT]))
 {
  $ebox=new GtkEventBox();
  $ebox->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);
  $align->add($ebox);
  $ebox->add($box);
 }
 else $align->add($box);
 
 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);
 $box->set_homogeneous($Xo[EQUALSIZE]);

 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$window;

 if($scrwnd) $scrwnd->show_all();
 else $align->show_all();
 $Xlast[firstWindow]=$window;
 $Xlast[firstWindowHidden]=$Xo[HIDDEN]; // saved to window visibility after parsing

 GulEvent($window,array('destroy'),array($Xo[ONUNLOAD]));
}





function GulBox()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 if(!$Xo[FLEX]) $Xo[FLEX]=0;
 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,1),$Xo[ORIENT]);
 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);

 if($Xo[ORIENT])
 {
  $Xo[ALIGN]=strtolower($Xo[ALIGN]);
  if($Xo[ALIGN]=='start'||$Xo[ALIGN]=='center'||$Xo[ALIGN]=='end') $flex2=0;
  else $flex2=1;
  if($Xo[ALIGN]=='left'||$Xo[ALIGN]=='right') $flex=0;
  else $flex=1;

  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0),$Xo[ALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkHBox();
 }
 else
 {
  if($Xo[ALIGN]) $flex=0; else $flex=1;
  if($Xo[VALIGN]) $flex2=0; else $flex2=1;
  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0),$Xo[ALIGN]);
  $Xo[VALIGN]=GulOptions(array('top','middle','bottom'),array(0,0.5,1,0),$Xo[VALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkVBox();
 }
 //$box->set_spacing(5);

 $ebox=new GtkEventBox();
 if(isset($Xo[CONTEXT])) $ebox->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);

 $Xo[OVERFLOW]=GulOptions(array('auto','scroll'),array(1,2,0),$Xo[OVERFLOW]);
 if($Xo[OVERFLOW])
 {
  $scrwnd=new GtkScrolledWindow();
  if($Xo[OVERFLOW]==1) $scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  if($Xo[OVERFLOW]==2) $scrwnd->set_policy(Gtk::POLICY_ALWAYS,Gtk::POLICY_ALWAYS);

  $scrwnd->add_with_viewport($ebox);
  $scrwnd->child->set_shadow_type(0);
  $ebox->add($align);
  $align->add($box);

  GulStyle($Xlast[$Yn][STYLE],$scrwnd,$ebox,'','','',$align,$box);
  GulPack($scrwnd,$Xo[FLEX]);

  $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
  if(!$Xo[HIDDEN]) $scrwnd->show_all();
 }
 else
 {
  $ebox->add($align);
  $align->add($box);

  GulStyle($Xlast[$Yn][STYLE],$box,$ebox,'','','',$align);
  GulPack($ebox,$Xo[FLEX]);

  $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
  if(!$Xo[HIDDEN]) $ebox->show_all();
 }

 $box->set_homogeneous($Xo[EQUALSIZE]);
 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$box;

 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}






function GulStack()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;
 
 $fixed=new gtkFixed();

 $ebox= new GtkEventBox();
 if(isset($Xo[CONTEXT])) $ebox->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);

 $Xo[OVERFLOW]=GulOptions(array('auto','scroll'),array(1,2,0),$Xo[OVERFLOW]);
 if($Xo[OVERFLOW])
 {
  $scrwnd=new GtkScrolledWindow();
  if($Xo[OVERFLOW]==1) $scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  if($Xo[OVERFLOW]==2) $scrwnd->set_policy(Gtk::POLICY_ALWAYS,Gtk::POLICY_ALWAYS);

  $scrwnd->add_with_viewport($ebox);
  $scrwnd->child->set_shadow_type(0);
  $ebox->add($fixed);

  GulStyle($Xlast[$Yn][STYLE],$scrwnd,$ebox,'','','','',$fixed);
  GulPack($scrwnd,$Xo[FLEX]);
  
  $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
  if(!$Xo[HIDDEN]) $scrwnd->show_all();
 }
 else
 {
  $ebox->add($fixed);
  GulStyle($Xlast[$Yn][STYLE],$fixed,$ebox);
  GulPack($ebox,$Xo[FLEX]);
  
  $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
  if(!$Xo[HIDDEN]) $ebox->show_all();
 }

 $Xwidgets[$Yn]=$fixed;
 if($Xo[ID]) $Guls[$Xo[ID]]=$fixed;

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ebox->show_all();

 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}





function GulSplitter()
{
 global $Xo,$Yn,$Xwidgets,$Xwidgetsn,$Guls,$Xlast;

 $name=$Xwidgets[$Yn-1]->get_name();
 if($name=='GtkHBox') $pan=new GtkHpaned();
 else $pan=new GtkVpaned();

 $ebox= new GtkEventBox();
 $ebox->add($pan);
 GulStyle($Xlast[$Yn][STYLE],$pan,$ebox);

 $frame1=new GtkFrame();
 $pan->add1($frame1);
 $box1=new GtkHbox();
 $frame1->add($box1);
 $frame1->show_all();
 //$Xwidgets[$Yn]->parent->parent->reparent($box1);
 $childs=$Xwidgets[$Yn-1]->get_children();
 foreach($childs as $c) $c->reparent($box1);

 GulPack($ebox,1);

 $frame2=new GtkFrame();
 $pan->add2($frame2);

 $name=$Xwidgets[$Yn-1]->get_name();
 if($name=='GtkVBox') $box2=new GtkVbox();
 else $box2=new GtkHbox();

 $frame2->add($box2);
 $frame2->show_all();
 
 if(isset($Xo[POSITION])) $pan->set_position(str_replace('px','',strtolower($Xo[POSITION])));

 $Xwidgets[$Yn-1]=$box2;
 if($Xo[ID]) $Guls[$Xo[ID]]=$pan;

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ebox->show_all();
}






function GulGrid()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $ebox=new GtkEventBox();
 $table=new GtkTable();
 $ebox->add($table);
 $Xlast[table]++;
 
 $Xlast[tableColumns][$Xlast[table]]=0;
 $Xlast[tableRows][$Xlast[table]]=0;

 GulStyle($Xlast[$Yn][STYLE],$table,$ebox,'','','','',$table);
 GulPack($ebox,$Xo[FLEX]);

 $Xwidgets[$Yn]=$table;
 if($Xo[ID]) $Guls[$Xo[ID]]=$table;

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ebox->show_all();
}


function GulColumn()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xlast[tableColumns][$Xlast[table]]++;
 if(!$Xo[FLEX]) $Xo[FLEX]=0;
 $Xlast[tableFlexColumns][$Xlast[table]][($Xlast[tableColumns][$Xlast[table]])]=$Xo[FLEX];
 if($Xlast[tableRows][$Xlast[table]]>0&&$Xlast[tableColumns][$Xlast[table]]>0) $Xwidgets[$Yn-2]->resize($Xlast[tableRows][$Xlast[table]],$Xlast[tableColumns][$Xlast[table]]);
}


function GulRow()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xlast[tableRows][$Xlast[table]]++;

 if(!$Xo[FLEX]) $Xo[FLEX]=0;
 $Xlast[tableFlexRows][$Xlast[table]][($Xlast[tableRows][$Xlast[table]])]=$Xo[FLEX];
 if($Xlast[tableRows][$Xlast[table]]>0&&$Xlast[tableColumns][$Xlast[table]]>0) $Xwidgets[$Yn-2]->resize($Xlast[tableRows][$Xlast[table]],$Xlast[tableColumns][$Xlast[table]]);
}











function GulTabBox()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;
 
 $ntbk=new GtkNotebook();
 
 if(!isset($Xo[SELECTEDINDEX])) $Xo[SELECTEDINDEX]=0;
 $Xlast[tabSelected][$Yn]=$Xo[SELECTEDINDEX];

 $Xlast[tabhidden]=GulOptions(array('true'),array(1,0),$Xo[HIDDEN]);

 GulStyle($Xlast[$Yn][STYLE],$ntbk,$ntbk);
 GulPack($ntbk,$Xo[FLEX]);
 
 $Xwidgets[$Yn]=$ntbk;
 if($Xo[ID]) $Guls[$Xo[ID]]=$ntbk;
 
 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ntbk->show_all();
}


function GulTab()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,1),$Xo[ORIENT]);
 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);

 if($Xo[ORIENT])
 {
  $Xo[ALIGN]=strtolower($Xo[ALIGN]);
  if($Xo[ALIGN]=='start'||$Xo[ALIGN]=='center'||$Xo[ALIGN]=='end') $flex2=0;
  else $flex2=1;
  if($Xo[ALIGN]=='left'||$Xo[ALIGN]=='right') $flex=0;
  else $flex=1;

  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0),$Xo[ALIGN]);
  $align=new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box=new GtkHBox();
 }
 else
 {
  if($Xo[ALIGN]) $flex=0; else $flex=1;
  if($Xo[VALIGN]) $flex2=0; else $flex2=1;

  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0),$Xo[ALIGN]);
  $Xo[VALIGN]=GulOptions(array('top','middle','bottom'),array(0,0.5,1,0),$Xo[VALIGN]);
  $align=new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box=new GtkVBox();
 }

 $ebox=new GtkEventBox();
 $ebox->add($align);
 $align->add($box);

 // wimp ebox bug correction
 /* $theme=get_class($Xwidgets[$Yn-1]->rc_get_style());
 if($theme=='MswStyle') $Xlast[$Yn][STYLE]='background-color:#F0F0EA;normal-background-color:white;'.$Xlast[$Yn][STYLE]; */
 $ebox->set_visible_window(false);


 if(isset($Xo[IMAGE])&&is_file($Xo[IMAGE]))
 {
  $i=GtkImage::new_from_file($Xo[IMAGE]);
  if($i)
  {
   if($Xlast[$Yn][DIR]) $box->pack_start($i);
   else $box->pack_end($i);
  }
 }

 if(isset($Xo[LABEL]))
 {
  $label=new gtkLabel(utf8_decode($Xo[LABEL]));
  GulStyle($Xlast[$Yn][STYLE],$box,$ebox,$label,'','',$align);
  $box->pack_start($label);
 }
 else GulStyle($Xlast[$Yn][STYLE],$box,$ebox,'','','',$align);

 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$box;

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ebox->show_all();

 $boxp=new GtkVbox();
 $Xlast[tabpage][$Xlast[tabcounter]]=$boxp;

 $Xwidgets[$Yn-1]->append_page($boxp,$ebox);
 if($Xo[ID]) $Guls[$Xo[ID]]=$box;
 if(!$Xlast[tabhidden]) $Xwidgets[$Yn-1]->show_all();

 $Xlast[tabcounter]++;
 
 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}


function GulTabpanel()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xwidgets[$Yn-1]=$Xlast[tabpage][$Xlast[tabcounter]];

 $Xo[FLEX]=$Xo[FLEX]||$Xlast[tabpanelsFlex];
 if(!$Xo[FLEX]) $Xo[FLEX]=0;
 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,1),$Xo[ORIENT]);
 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);

 if($Xo[ORIENT])
 {
  $Xo[ALIGN]=strtolower($Xo[ALIGN]);
  if($Xo[ALIGN]=='start'||$Xo[ALIGN]=='center'||$Xo[ALIGN]=='end') $flex2=0;
  else $flex2=1;
  if($Xo[ALIGN]=='left'||$Xo[ALIGN]=='right') $flex=0;
  else $flex=1;

  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0),$Xo[ALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkHBox();
 }
 else
 {
  if($Xo[ALIGN]) $flex=0; else $flex=1;
  if($Xo[VALIGN]) $flex2=0; else $flex2=1;

  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0),$Xo[ALIGN]);
  $Xo[VALIGN]=GulOptions(array('top','middle','bottom'),array(0,0.5,1,0),$Xo[VALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkVBox();
 }
 //$box->set_spacing(5);

 $ebox= new GtkEventBox();
 if(isset($Xo[CONTEXT])) $ebox->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);

 // wimp ebox bug correction
 /*$theme=get_class($Xwidgets[$Yn-1]->rc_get_style());
 if($theme=='MswStyle')
 {
  $Xlast[$Yn][STYLE]='background-color:white;'.$Xlast[$Yn][STYLE];
  $Xwidgets[$Yn-1]->set_border_width(1);
 }
   */
 $ebox->set_visible_window(false);

 $Xo[OVERFLOW]=GulOptions(array('auto','scroll'),array(1,2,0),$Xo[OVERFLOW]);
 if($Xo[OVERFLOW])
 {
  $scrwnd=new GtkScrolledWindow();
  if($Xo[OVERFLOW]==1) $scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  if($Xo[OVERFLOW]==2) $scrwnd->set_policy(Gtk::POLICY_ALWAYS,Gtk::POLICY_ALWAYS);

  $scrwnd->add_with_viewport($ebox);
  $scrwnd->child->set_shadow_type(0);
  $ebox->add($align);
  $align->add($box);
  $Xwidgets[$Yn-1]->pack_start($scrwnd,$Xo[FLEX],$Xo[FLEX]);

  GulStyle('padding:5px;'.$Xlast[$Yn][STYLE],$scrwnd,$ebox,'','','',$align,$box);
  
  $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
  if(!$Xo[HIDDEN]) $scrwnd->show_all();
 }
 else
 {
  $ebox->add($align);
  $align->add($box);
  $Xwidgets[$Yn-1]->pack_start($ebox,$Xo[FLEX],$Xo[FLEX]);

  GulStyle('padding:5px;'.$Xlast[$Yn][STYLE],$box,$ebox,'','','',$align);
  $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
  if(!$Xo[HIDDEN]) $ebox->show_all();
  
 }

 $box->set_homogeneous($Xo[EQUALSIZE]);
 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$box;

 $Xlast[tabcounter]++;
 
 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}





function GulGroup()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $frame = new gtkFrame();
 
 if(!$Xo[FLEX]) $Xo[FLEX]=0;
 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,0),$Xo[ORIENT]);
 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);

 if($Xo[ORIENT])
 {
  $Xo[ALIGN]=strtolower($Xo[ALIGN]);
  if($Xo[ALIGN]=='start'||$Xo[ALIGN]=='center'||$Xo[ALIGN]=='end') $flex2=0;
  else $flex2=1;
  if($Xo[ALIGN]=='left'||$Xo[ALIGN]=='right') $flex=0;
  else $flex=1;

  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0),$Xo[ALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkHBox();
 }
 else
 {
  if($Xo[ALIGN]) $flex=0; else $flex=1;
  if($Xo[VALIGN]) $flex2=0; else $flex2=1;
  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0),$Xo[ALIGN]);
  $Xo[VALIGN]=GulOptions(array('top','middle','bottom'),array(0,0.5,1,0),$Xo[VALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkVBox();
 }
 //$box->set_spacing(5);

  
 $ebox= new GtkEventBox();
 if(isset($Xo[CONTEXT])) $ebox->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);

 $Xo[OVERFLOW]=GulOptions(array('auto','scroll'),array(1,2,0),$Xo[OVERFLOW]);
 if($Xo[OVERFLOW])
 {
  $scrwnd=new GtkScrolledWindow();
  if($Xo[OVERFLOW]==1) $scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  if($Xo[OVERFLOW]==2) $scrwnd->set_policy(Gtk::POLICY_ALWAYS,Gtk::POLICY_ALWAYS);

  $frame->add($scrwnd);
  $scrwnd->add_with_viewport($ebox);
  $scrwnd->child->set_shadow_type(0);
  $ebox->add($align);
  $align->add($box);
 }
 else
 {
  $frame->add($ebox);
  $ebox->add($align);
  $align->add($box);
 }

 GulStyle('padding:5px;'.$Xlast[$Yn][STYLE],$box,$ebox,'','','',$align);
 GulPack($frame,$Xo[FLEX]);
 
 $box->set_homogeneous($Xo[EQUALSIZE]);
 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$frame;
 
 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $frame->show_all();
 
 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}




function GulCaption()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,1),$Xo[ORIENT]);
 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);

 if($Xo[ORIENT])
 {
  $Xo[ALIGN]=strtolower($Xo[ALIGN]);
  if($Xo[ALIGN]=='start'||$Xo[ALIGN]=='center'||$Xo[ALIGN]=='end') $flex2=0;
  else $flex2=1;
  if($Xo[ALIGN]=='left'||$Xo[ALIGN]=='right') $flex=0;
  else $flex=1;

  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0),$Xo[ALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkHBox();
 }
 else
 {
  if($Xo[ALIGN]) $flex=0; else $flex=1;
  if($Xo[VALIGN]) $flex2=0; else $flex2=1;
  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0),$Xo[ALIGN]);
  $Xo[VALIGN]=GulOptions(array('top','middle','bottom'),array(0,0.5,1,0),$Xo[VALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkVBox();
 }
 //$box->set_spacing(5);

 $ebox=new GtkEventBox();
 if(isset($Xo[CONTEXT])) $ebox->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);

 $ebox->add($align);
 $align->add($box);

 if(isset($Xo[IMAGE])&&is_file($Xo[IMAGE]))
 {
   $i=GtkImage::new_from_file($Xo[IMAGE]);
   if($i)
   {
    if($Xlast[$Yn][DIR]) $box->pack_start($i);
    else $box->pack_end($i);
   }
  }

  if(isset($Xo[LABEL]))
  {
   $label=new gtkLabel(utf8_decode($Xo[LABEL]));
   GulStyle($Xlast[$Yn][STYLE],$ebox,$ebox,$label,'','',$align);
   if($Xlast[$Yn][DIR]) $box->pack_start($label);
   else $box->pack_end($label);
  }
  else GulStyle($Xlast[$Yn][STYLE],$ebox,$ebox,'','','',$align);

 $box->set_homogeneous($Xo[EQUALSIZE]);
 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$box;


 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ebox->show_all();

 $name=$Xwidgets[$Yn-1]->parent->parent->parent->get_name();
 if($name=='GtkFrame') $Xwidgets[$Yn-1]->parent->parent->parent->set_label_widget($ebox);
 else $Xwidgets[$Yn-1]->parent->parent->parent->parent->parent->set_label_widget($ebox);

 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}





function GulToolTipPopup()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xlast[tooltip][$Xo[ID]]=$Xo[LABEL];
 $Xlast[tooltipid]=$Xo[ID];
 $Xwidgets[$Yn]=$Xwidgets[$Yn-1];
}



function GulPopup()
{
 global $Xo,$Yn,$Xwidgets,$Xwidgetsn,$Guls,$Xlast,$Gulpopups;

 $menu = new GtkMenu();
 $Xwidgets[$Yn]=$menu;
 GulStyle($Xlast[$Yn][STYLE],$menu,$menu);

 if($Xwidgets[$Yn-1]) $t=$Xwidgets[$Yn-1]->get_name();
 if($t=='GtkMenuItem') $Xwidgets[$Yn-1]->set_submenu($menu);

 if($Xwidgetsn[$Yn-1]=='BUTTON') $Xwidgets[$Yn-1]->parent->parent->parent->connect('button-press-event','GulShowPopup2','',$menu);
 //$t=$Xwidgets[$Yn-1]->parent->parent->parent->get_name();
 //if($t=='GtkButton') $Xwidgets[$Yn-1]->parent->parent->parent->connect('button-press-event','GulShowPopup2','',$menu);

 if($Xo[ID])
 {
  $Guls[$Xo[ID]]=$menu;
  $Gulpopups[$Xo[ID]]=$menu;
 }
}




function GulSubMenu()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $item = new GtkMenuItem(utf8_decode($Xo[LABEL]));
 $Xwidgets[$Yn]=$item;
 $Xwidgets[$Yn-1]->append($item);

 GulStyle($Xlast[$Yn][STYLE],$item,$item,$item->child);

 if($Xo[ID]) $Guls[$Xo[ID]]=$item;
 
 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $item->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $item->show_all();
}




function GulMenuItem()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xo[ACCESSKEY]=utf8_decode($Xo[ACCESSKEY]);
 $Xo[LABEL]=utf8_decode($Xo[LABEL]);

 if(isset($Xo[ACCESSKEY]))
 {
  $ok=1;
  for($i=0;$i<strlen($Xo[LABEL]);$i++)
  {
   if($ok&&$Xo[ACCESSKEY]==$Xo[LABEL]{$i}) { $label.='_'.$Xo[LABEL]{$i}; $ok=0; }
   else $label.=$Xo[LABEL]{$i};
  }
  $Xo[LABEL]=$label;
 }

 $Xo[TYPE]=strtolower($Xo[TYPE]);
 if(isset($Xo[IMAGE]))
 {
  $item = new GtkImageMenuItem($Xo[LABEL]);
  if(is_file($Xo[IMAGE])) if($i=GtkImage::new_from_file($Xo[IMAGE])) $item->set_image($i);
 }
 else if($Xo[TYPE]=='radio')
 {
  $item = new GtkRadioMenuItem(null,$Xo[LABEL]);
  if(isset($Xo[NAME]))
  {
   if(!$Xlast[radiogroup][$Xo[NAME]]) $Xlast[radiogroup][$Xo[NAME]]=$item;
   else $item->set_group($Xlast[radiogroup][$Xo[NAME]]);
   $item->set_active(GulOptions(array('true'),array(1,0),$Xo[CHECKED]));
  }
 }
 else if($Xo[TYPE]=='checkbox')
 {
  $item = new GtkCheckMenuItem($Xo[LABEL]);
  $item->set_active(GulOptions(array('true'),array(1,0),$Xo[CHECKED]));
 }
 else $item = new GtkMenuItem($Xo[LABEL]);

 $Xwidgets[$Yn]=$item;
 $Xwidgets[$Yn-1]->append($item);
 if($Xo[ID]) $Guls[$Xo[ID]]=$item;

 GulStyle($Xlast[$Yn][STYLE],$item,$item,$item->child);

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($Xwidgets[$Yn],$Xo[TOOLTIPTEXT]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $item->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $item->show_all();

 GulEvent($item,array('activate','activate','select','deselect'),array($Xo[ONCOMMAND],$Xo[ONCLICK],$Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT]));
}





function GulMenuSeparator()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;
 
 $item = new GtkSeparatorMenuItem();

 $Xwidgets[$Yn-1]->append($item);
 if($Xo[ID]) $Guls[$Xo[ID]]=$item;

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $item->show_all();
}








function GulButton()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 if(!$Xo[FLEX]) $Xo[FLEX]=0;

 if(isset($Xo[ICON])&&$Xo[ICON]=GulOptions(array('accept','cancel','help','open','save','find','clear',
 'yes','no','apply','close','print','add','remove','refresh','go-forward','go-back','properties,select-font,
 select-color,network'), array('Gtk::STOCK_APPLY','Gtk::STOCK_CANCEL','Gtk::STOCK_HELP','Gtk::STOCK_OPEN',
 'Gtk::STOCK_SAVE','Gtk::STOCK_FIND','Gtk::STOCK_CLEAR','Gtk::STOCK_YES','Gtk::STOCK_NO','Gtk::STOCK_APPLY',
 'Gtk::STOCK_CLOSE','Gtk::STOCK_PRINT','Gtk::STOCK_ADD','Gtk::STOCK_REMOVE','Gtk::STOCK_REFRESH',
 'Gtk::STOCK_GO_FORWARD','Gtk::STOCK_GO_BACK','Gtk::STOCK_PROPERTIES','Gtk::STOCK_SELECT_FONT',
 'Gtk::STOCK_SELECT_COLOR','Gtk::STOCK_NETWORK',0),$Xo[ICON]))
 {
  if($Xo[TYPE]=='checkbox') eval('$button=GtkButton::new_from_stock('.$Xo[ICON].');');
  GulStyle($Xlast[$Yn][STYLE],$button,$button);
 }
 else
 {

  if($Xo[TYPE]=='checkbox')
  {
   $button=new GtkToggleButton();
   $button->set_active(GulOptions(array('true'),array(1,0),$Xo[CHECKED]));
  }
  else $button=new GtkButton();

  $box0=new gtkHbox();
  $button->add($box0);

  if($Xo[ALIGN]) $flex=0;
  else $flex=1;

  $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
  $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,1),$Xo[ORIENT]);

  if($Xo[ORIENT])
  {
   $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0.5),$Xo[ALIGN]);
   $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0.5),$Xo[ALIGN]);
   if($Xo[ALIGN]!=0.5) $Xo[VALIGN]=0;
   $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],0,0);
   $box = new GtkHBox();
  }
  else
  {
   $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0.5),$Xo[ALIGN]);
   $align = new GtkAlignment($Xo[ALIGN],0.5,0,0);
   $box = new GtkVBox();
  }
  $box0->pack_start($align,1,1);
  $align->add($box);

  if(isset($Xo[IMAGE])&&is_file($Xo[IMAGE]))
 {
   $i=GtkImage::new_from_file($Xo[IMAGE]);
   if($i)
   {
    if($Xlast[$Yn][DIR]) $box->pack_start($i);
    else $box->pack_end($i);
   }
  }

  if(isset($Xo[LABEL]))
  {
   $label=new gtkLabel(utf8_decode($Xo[LABEL]));
   GulStyle($Xlast[$Yn][STYLE],$button,$button,$label,'','',$align);
   if($Xlast[$Yn][DIR]) $box->pack_start($label);
   else $box->pack_end($label);
  }
  else GulStyle($Xlast[$Yn][STYLE],$button,$button,'','','',$align);

  $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);
  $box->set_homogeneous($Xo[EQUALSIZE]);

 }

 if(isset($Xo[CONTEXT])) $button->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);
 if(isset($Xo[POPUP])) $button->connect('button-press-event','GulShowPopup2',$Xo[POPUP]);

 GulPack($button,$Xo[FLEX]);

 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$button;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($button,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($button,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $button->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $button->show_all();

 GulEvent($button,array('clicked','clicked','enter','leave'),array($Xo[ONCOMMAND],$Xo[ONCLICK],$Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT]));
}







function GulTextBox()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xo[MULTILINE]=GulOptions(array('true'),array(1,0),$Xo[MULTILINE]);
 $Xo[TYPE]=strtolower($Xo[TYPE]);
 if($Xo[MULTILINE])
 {
  // textview
  $textB = new GtkTextBuffer();
  $textV = new GtkTextView();
  $textV->set_buffer($textB);
  if(isset($Xo[VALUE])) $textB->set_text(utf8_decode($Xo[VALUE]));

  GulStyle($Xlast[$Yn][STYLE],'','',$textV,'modify_text');
  
  $scrwnd = new GtkScrolledWindow();
  $scrwnd->add($textV);
  $scrwnd->set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC);

  GulPack($scrwnd,$Xo[FLEX]);
  
  if(!$Xo[COLS]) $Xo[COLS]=20;
  if(!$Xo[ROWS]) $Xo[ROWS]=3;
  $Xo[ROWS]=$Xo[ROWS]*$Xlast[lastfontsize]*1.33;
  $Xo[COLS]=$Xo[COLS]*$Xlast[lastfontsize]/1.5;
  $scrwnd->set_size_request(round($Xo[COLS]),round($Xo[ROWS]));
 }
 else
 {
  // entry
  $textV = new GtkEntry();
  if(isset($Xo[VALUE])) $textV->set_text(utf8_decode($Xo[VALUE]));
  if($Xo[TYPE]=='password') $textV->set_visibility(0);
  if(isset($Xo[MAXLENGTH])) $textV->set_max_length($Xo[MAXLENGTH]);
  if(!$Xo[SIZE]) $Xo[SIZE]=20;

  GulStyle($Xlast[$Yn][STYLE],'','',$textV,'modify_text');

  $textV->set_size_request(round($Xo[SIZE]*$Xlast[lastfontsize]/1.75),round(1.8*$Xlast[lastfontsize]));

  GulPack($textV,0);
 }

 if(GulOptions(array('true'),array(1,0),$Xo[READONLY])) $textV->set_editable(0);

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($textV,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($textV,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xwidgets[$Yn]=$textV;
 if($Xo[ID]) $Guls[$Xo[ID]]=$textV;

 if($scrwnd) GulStyle($Xlast[$Yn][STYLE],$scrwnd,'','','',$textV,$textV);
 else GulStyle($Xlast[$Yn][STYLE],$textV,'','','',$textV,$textV);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $textV->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN])
 {
  $textV->show_all();
  if($scrwnd) $scrwnd->show_all();
 }

 if($scrwnd) GulEvent($textB,array('changed'),array($Xo[ONINPUT]));
 else GulEvent($textV,array('changed','activate'),array($Xo[ONINPUT],$Xo[ONCHANGE]));
}







function GulLabel()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 if($Xlast[$Yn-1][ALIGN]&&!$Xo[ALIGN]) $Xo[ALIGN]=$Xlast[$Yn-1][ALIGN];
 if(!$Xo[FLEX]) $Xo[FLEX]=0;

 $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0),$Xo[ALIGN]);
 $Xo[ALIGN]=GulOptions(array('left','center','right'),array(0,0.5,1,0),$Xo[ALIGN]);

 $label = new GtkLabel(utf8_decode($Xo[VALUE]));
 $label->set_alignment($Xo[ALIGN],$Xo[VALIGN]);

 $ebox= new GtkEventBox();
 if(isset($Xo[CONTEXT])) $ebox->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);
 GulPack($ebox,$Xo[FLEX]);
 $ebox->add($label);

 GulStyle($Xlast[$Yn][STYLE],$label,$ebox,$label,'','',$label);

 $Xwidgets[$Yn]=$label;
 if($Xo[ID]) $Guls[$Xo[ID]]=$label;

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $label->set_sensitive($Xo[DISABLED]);
 
 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ebox->show_all();
}







function GulCheck()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 if(!$Xo[FLEX]) $Xo[FLEX]=0;
 if(!$Xo[IMAGE]&&$Xo[SRC]) $Xo[IMAGE]=$Xo[SRC];
 
 $button = new GtkCheckButton();
 if(strtolower($Xo[CHECKED])=='true') $button->set_active(1);

 $box0=new gtkHbox();
 $button->add($box0);

 if($Xo[ALIGN]) $flex=0;
 else $flex=1;

 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,1),$Xo[ORIENT]);

 if($Xo[ORIENT])
 {
  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0.5),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0.5),$Xo[ALIGN]);
  if($Xo[ALIGN]!=0.5) $Xo[VALIGN]=0;
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],0,0);
  $box = new GtkHBox();
 }
 else
 {
  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0.5),$Xo[ALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],0.5,0,0);
  $box = new GtkVBox();
 }
 $box0->pack_start($align,1,1);
 $align->add($box);

 if(isset($Xo[IMAGE])&&is_file($Xo[IMAGE]))
 {
  $i=GtkImage::new_from_file($Xo[IMAGE]);
  if($i)
  {
   if($Xlast[$Yn][DIR]) $box->pack_start($i);
   else $box->pack_end($i);
  }
 }

 if(isset($Xo[LABEL]))
 {
  $label=new gtkLabel(utf8_decode($Xo[LABEL]));
  GulStyle($Xlast[$Yn][STYLE],$button,$button,$label,'','',$align);

  if($Xlast[$Yn][DIR]) $box->pack_start($label);
  else $box->pack_end($label);
 }
 else GulStyle($Xlast[$Yn][STYLE],$button,$button,'','','',$align);

 if(isset($Xo[CONTEXT])) $button->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);
 if(isset($Xo[POPUP])) $button->connect('button-press-event','GulShowPopup2',$Xo[POPUP]);

 GulPack($button,$Xo[FLEX]);

 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);
 $box->set_homogeneous($Xo[EQUALSIZE]);

 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$button;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($button,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($button,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $button->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $button->show_all();

 GulEvent($button,array('toggled','toggled','enter','leave'),array($Xo[ONCOMMAND],$Xo[ONCLICK],$Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT]));
}








function GulRadio()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 if(!$Xo[FLEX]) $Xo[FLEX]=0;
 if(!$Xo[IMAGE]&&$Xo[SRC]) $Xo[IMAGE]=$Xo[SRC];

 $button=new GtkRadioButton($Xlast[radio]);
 if($Xlast[radiogroup]==1) $Xlast[radio]=$button;
 else $Xlast[radio]=null;

 if($Xlast[radiogroupvalue])
 {
  if($Xlast[radiogroupvalue]==$Xo[LABEL]) $Xo[SELECTED]='true';
  else $Xo[SELECTED]='';
 }
 if(strtolower($Xo[SELECTED])=='true') $button->set_active(1);

 $box0=new gtkHbox();
 $button->add($box0);

 if($Xo[ALIGN]) $flex=0;
 else $flex=1;

 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,1),$Xo[ORIENT]);

 if($Xo[ORIENT])
 {
  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0.5),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0.5),$Xo[ALIGN]);
  if($Xo[ALIGN]!=0.5) $Xo[VALIGN]=0;
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],0,0);
  $box = new GtkHBox();
 }
 else
 {
  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0.5),$Xo[ALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],0.5,0,0);
  $box = new GtkVBox();
 }
 $box0->pack_start($align,1,1);
 $align->add($box);

 if(isset($Xo[IMAGE])&&is_file($Xo[IMAGE]))
 {
  $i=GtkImage::new_from_file($Xo[IMAGE]);
  if($i)
  {
   if($Xlast[$Yn][DIR]) $box->pack_start($i);
   else $box->pack_end($i);
  }
 }

 if(isset($Xo[LABEL]))
 {
  $label=new gtkLabel(utf8_decode($Xo[LABEL]));
  GulStyle($Xlast[$Yn][STYLE],$button,$button,$label,'','',$align);
  if($Xlast[$Yn][DIR]) $box->pack_start($label);
  else $box->pack_end($label);
 }
 else GulStyle($Xlast[$Yn][STYLE],$button,$button,'','','',$align);

 if(isset($Xo[CONTEXT])) $button->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);
 if(isset($Xo[POPUP])) $button->connect('button-press-event','GulShowPopup2',$Xo[POPUP]);

 GulPack($button,$Xo[FLEX]);

 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);
 $box->set_homogeneous($Xo[EQUALSIZE]);

 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$button;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($button,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($button,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $button->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $button->show_all();

 GulEvent($button,array('toggled','toggled','enter','leave'),array($Xo[ONCOMMAND],$Xo[ONCLICK],$Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT]));
 
}










function GulListBox()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;
 if(!$Xo[FLEX]) $Xo[FLEX]=0;

 $treeview = new GtkTreeView();
 $treeview->set_headers_visible(0);
 $selection=$treeview->get_selection();
 if(strtolower($Xo[SELTYPE])=='multiple') $selection->set_mode(Gtk::SELECTION_MULTIPLE);

 $cell_renderer = new GtkCellRendererText();
 $col1 = new GtkTreeViewColumn('', $cell_renderer, 'text', 0);
 $col1->set_resizable(0);
 $treeview->append_column($col1);

 $Xwidgets[$Yn]=$treeview;
 if($Xo[ID]) $Guls[$Xo[ID]]=$treeview;

 $scrwnd = new GtkScrolledWindow();
 $scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
 $scrwnd->add($treeview);

 GulStyle('width:200;'.$Xlast[$Yn][STYLE],$scrwnd);
 GulStyle($Xlast[$Yn][STYLE],$treeview);

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($treeview,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($treeview,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 GulPack($scrwnd,$Xo[FLEX]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $treeview->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $scrwnd->show_all();

 GulEvent($selection,array('changed'),array($Xo[ONSELECT]));
}



function GulListBox2()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast,$GulListSavedstyle,$GulListcounter;

  $ncols=$Xlast[colHeadNumber];
  if($Xlast[colCellNumber]>$ncols) $ncols=$Xlast[colCellNumber];
  if($Xlast[colTotalCellNumber]>$ncols) $ncols=$Xlast[colTotalCellNumber];
  if($ncols<1) $ncols=1;

  $s='$store = new GtkListStore(';
  for($i=0; $i<$ncols; $i++)
  {
   if($i) $s.=',';
   $s.='Gtk::TYPE_STRING';

   if($i>0)
   {
    $cell_renderer = new GtkCellRendererText();
    if($Xlast[colItemTitle][$i]) $ok=1;
    $col = new GtkTreeViewColumn(utf8_decode($Xlast[colItemTitle][$i]),$cell_renderer,'text',$i);
    $Xwidgets[$Yn]->append_column($col);
   }
    else
    {
     $col=$Xwidgets[$Yn]->get_column(0);
     if($Xlast[colItemTitle][0]) $ok=1;
     $col->set_title(utf8_decode($Xlast[colItemTitle][0]));
     if(!isset($Xlast[colItemFlex][0])) $Xlast[colItemFlex][0]=1;
    }
    $col->set_expand($Xlast[colItemFlex][$i]);
    $Xo[ID]=$Xlast[colItemTitleId][$Xlast[colHeadNumber]];
    if($Xo[ID]) $Guls[$Xo[ID]]=$col;

    $align=new GtkAlignment();
    $col->set_widget($align);
    $align->show();
    $w=$Xlast[colItemTitleWidget][$i];
    if($w) $w->reparent($align);

  }
  $s.=');';
  eval($s);

  if($ok) $Xwidgets[$Yn]->set_headers_visible(1);

  for($i=0; $i<$Xlast[colItemNumber]; $i++)
  {
   $tab='';
   for($j=0;$j<$ncols;$j++) $tab[]=$Xlast[colCellLabel][$i][$j];
   if($tab) $store->append($tab);
  }
  $Xwidgets[$Yn]->set_model($store);
}






function GulcolorPicker()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;
 
 if($Xo[TYPE]=='button')
 {
  $colorp=new GtkColorButton();
  if($Xo[COLOR]) $colorp->set_color(GdkColor::parse(returnCSSColor($Xo[COLOR])));
  GulEvent($colorp,array('color-set'),array($Xo[ONSELECT]));
 }
 else
 {
  $colorp=new GtkColorSelection();
  if($Xo[COLOR]) $colorp->set_current_color(GdkColor::parse(returnCSSColor($Xo[COLOR])));
  GulEvent($colorp,array('color-changed'),array($Xo[ONCLICK]));
 }

 GulPack($colorp,$Xo[FLEX]);

 $Xwidgets[$Yn]=$colorp;
 if($Xo[ID]) $Guls[$Xo[ID]]=$colorp;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($colorp,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($colorp,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $colorp->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $colorp->show_all();
}




function GulMenuList()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $menu=&GtkComboBoxEntry::new_text();
 $entry=$menu->get_child();
 if(isset($Xo[LABEL])) $entry->set_text(utf8_decode($Xo[LABEL]));
 if($Xo[EDITABLE]=='true') $entry->set_editable(1);
 else $entry->set_editable(0);

 GulStyle($Xlast[$Yn][STYLE],'','',$entry,'modify_text');
 GulStyle($Xlast[$Yn][STYLE],$menu,'','','',$entry);
 
 GulPack($menu,$Xo[FLEX]);

 $Xwidgets[$Yn]=$menu;
 if($Xo[ID]) $Guls[$Xo[ID]]=$menu;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($entry,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($entry,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $menu->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $menu->show_all();
 
 GulEvent($menu,array('changed'),array($Xo[ONCHANGE]));
}


function GulMenuListItem()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xwidgets[$Yn-1]->append_text(utf8_decode($Xo[LABEL]));
}





function GulProgressMeter()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $bar=new GtkProgressBar();
 if(strtolower($Xo[MODE])=='undetermined') $bar->set_pulse_step(0.1);
 else
 {
  if(isset($Xo[VALUE])) $bar->set_fraction((str_replace('%','',$Xo[VALUE])/100));
 }

 GulStyle($Xlast[$Yn][STYLE],$bar,'','','',$bar);
 GulPack($bar,$Xo[FLEX]);

 $Xwidgets[$Yn]=$bar;
 if($Xo[ID]) $Guls[$Xo[ID]]=$bar;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($bar,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($bar,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $bar->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $bar->show_all();
}





function GulScale()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,1),$Xo[ORIENT]);

 if(!isset($Xo['MIN'])) $Xo['MIN']=0;
 if(!isset($Xo['MAX'])) $Xo['MAX']=1;
 if(!isset($Xo[INCREMENT])) $Xo[INCREMENT]=1;

 if($Xo[ORIENT]) $scale=&GtkHScale::new_with_range($Xo['MIN'],$Xo['MAX'],$Xo[INCREMENT]);
 else $scale=&GtkVScale::new_with_range($Xo['MIN'],$Xo['MAX'],$Xo[INCREMENT]);
 
 if(isset($Xo[VALUE])) $scale->set_value($Xo[VALUE]);

 GulStyle($Xlast[$Yn][STYLE],$scale,'','','',$scale);
 GulPack($scale,$Xo[FLEX]);

 $Xwidgets[$Yn]=$scale;
 if($Xo[ID]) $Guls[$Xo[ID]]=$scale;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($scale,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($scale,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $scale->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $scale->show_all();

 GulEvent($menu,array('value-changed'),array($Xo[ONCHANGE]));
}





function GulStatusBar()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $bar=new GtkStatusbar();
 $ebox= new GtkEventBox();
 $ebox->add($bar);

 GulStyle($Xlast[$Yn][STYLE],$bar,$ebox);
 GulPack($ebox,$Xo[FLEX]);

 $Xwidgets[$Yn]=$bar;
 if($Xo[ID]) $Guls[$Xo[ID]]=$bar;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($bar,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($bar,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $bar->set_sensitive($Xo[DISABLED]);

 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ebox->show_all();
}





function GulImage()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 if(!is_file($Xo[SRC]))
 {
  if($Xo[ONERROR]) eval($Xo[ONERROR]);
 }
 else
 {
  $img=GtkImage::new_from_file($Xo[SRC]);
  GulStyle($Xlast[$Yn][STYLE],$img);
  GulPack($img,0);

  $Xwidgets[$Yn]=$img;
  if($Xo[ID]) $Guls[$Xo[ID]]=$img;

  if(isset($Xo[TOOLTIPTEXT])) GulTooltip($img,$Xo[TOOLTIPTEXT]);
  if(isset($Xo[TOOLTIP])) GulTooltip($img,$Xlast[tooltip][$Xo[TOOLTIP]]);

  $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
  if(!$Xo[HIDDEN]) $img->show_all();
 }
}





function GulDeck()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $deck=new GtkNotebook();
 $deck->set_show_tabs(0);
 $deck->set_show_border(0);

 if(!isset($Xo[SELECTEDINDEX])) $Xo[SELECTEDINDEX]=0;
 $Xlast[deckSelected][$Yn]=$Xo[SELECTEDINDEX];

 GulPack($deck,$Xo[FLEX]);
 GulStyle($Xlast[$Yn][STYLE],$deck,$deck);

 $Xwidgets[$Yn]=$deck;
 if($Xo[ID]) $Guls[$Xo[ID]]=$deck;

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $deck->show_all();
}






function GulMenuBar()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $bar=new GtkMenuBar();

 $ebox=new GtkEventBox();
 $ebox->add($bar);

 GulStyle($Xlast[$Yn][STYLE],$bar,$bar); // note: bar is not transparent. don't use ebox color
 GulPack($ebox,$Xo[FLEX]);

 $Xwidgets[$Yn]=$bar;
 if($Xo[ID]) $Guls[$Xo[ID]]=$bar;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($bar,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($bar,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ebox->show_all();

 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}






function GulToolBox()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $tbox=new GtkHandleBox();

 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,0),$Xo[ORIENT]);
 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);

 if($Xo[ORIENT])
 {
  $Xo[ALIGN]=strtolower($Xo[ALIGN]);
  if($Xo[ALIGN]=='start'||$Xo[ALIGN]=='center'||$Xo[ALIGN]=='end') $flex2=0;
  else $flex2=1;
  if($Xo[ALIGN]=='left'||$Xo[ALIGN]=='right') $flex=0;
  else $flex=1;

  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0),$Xo[ALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkHBox();
 }
 else
 {
  if($Xo[ALIGN]) $flex=0; else $flex=1;
  if($Xo[VALIGN]) $flex2=0; else $flex2=1;
  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0),$Xo[ALIGN]);
  $Xo[VALIGN]=GulOptions(array('top','middle','bottom'),array(0,0.5,1,0),$Xo[VALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkVBox();
 }
 //$box->set_spacing(5);

 $ebox=new GtkEventBox();
 if(isset($Xo[CONTEXT])) $ebox->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);

 $tbox->add($ebox);
 $ebox->add($align);
 $align->add($box);

 $box->set_homogeneous($Xo[EQUALSIZE]);
 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$tbox;

 GulStyle($Xlast[$Yn][STYLE],$tbox,$ebox,'','','',$align);
 GulPack($tbox,$Xo[FLEX]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $tbox->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $tbox->show_all();

 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}






function GulToolBar()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $tb=new GtkToolbar();
 if(method_exists($tb,'set_toolbar_style')) $tb->set_toolbar_style(GulOptions(array('icons','text','full'),array(0,1,2,2),$Xo[MODE]));
 else $tb->set_style(GulOptions(array('icons','text','full'),array(0,1,2,2),$Xo[MODE]));

 $tb->set_tooltips(1);
 
 $ebox=new GtkEventBox();
 $ebox->add($tb);

 GulStyle($Xlast[$Yn][STYLE],$tb,$tb);
 GulPack($ebox,$Xo[FLEX]);

 $Xwidgets[$Yn]=$tb;
 if($Xo[ID]) $Guls[$Xo[ID]]=$tb;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($tb,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($tb,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $tb->set_sensitive($Xo[DISABLED]);
 
 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $ebox->show_all();
 
 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}



function GulToolBarButton()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $Xo[TYPE]=strtolower($Xo[TYPE]);
 $Xo[LABEL]=utf8_decode($Xo[LABEL]);

 if(isset($Xo[ICON])&&$Xo[ICON]=GulOptions(array('accept','cancel','help','open','save','find','clear',
 'yes','no','apply','close','print','add','remove','refresh','go-forward','go-back','properties,select-font,
 select-color,network'), array('Gtk::STOCK_APPLY','Gtk::STOCK_CANCEL','Gtk::STOCK_HELP','Gtk::STOCK_OPEN',
 'Gtk::STOCK_SAVE','Gtk::STOCK_FIND','Gtk::STOCK_CLEAR','Gtk::STOCK_YES','Gtk::STOCK_NO','Gtk::STOCK_APPLY',
 'Gtk::STOCK_CLOSE','Gtk::STOCK_PRINT','Gtk::STOCK_ADD','Gtk::STOCK_REMOVE','Gtk::STOCK_REFRESH',
 'Gtk::STOCK_GO_FORWARD','Gtk::STOCK_GO_BACK','Gtk::STOCK_PROPERTIES','Gtk::STOCK_SELECT_FONT',
 'Gtk::STOCK_SELECT_COLOR','Gtk::STOCK_NETWORK',0),$Xo[ICON]))
 {
   /*
   
   if($Xo[TYPE]=='checkbox')
   {
    eval('$button=GtkToggleToolButton::new_from_stock('.$Xo[ICON].');');
    $button->set_active(GulOptions(array('true'),array(1,0),$Xo[CHECKED]));
   }
   else if($Xo[TYPE]=='radio')
   {
    eval('$button=GtkRadioToolButton::new_from_stock('.$Xo[ICON].');');
    if(!$Xlast[radiotoolgroup][$Xo[NAME]]) $Xlast[radiotoolgroup][$Xo[NAME]]=$button;
    else $button->set_group($Xlast[radiotoolgroup][$Xo[NAME]]);
    $button->set_active(GulOptions(array('true'),array(1,0),$Xo[CHECKED]));
   }
   else eval('$button=GtkToolButton::new_from_stock('.$Xo[ICON].');');
   */

   /*if($Xo[TYPE]=='menu') eval('$button=GtkMenuToolButton::new_from_stock('.$Xo[ICON].');');
   else eval('$button=GtkToolButton::new_from_stock('.$Xo[ICON].');');
   */
   eval('$button=GtkToolButton::new_from_stock('.$Xo[ICON].');');

   GulStyle($Xlast[$Yn][STYLE],$button,$button);

 }
 else
 {
  if(isset($Xo[IMAGE])&&is_file($Xo[IMAGE])) $i=GtkImage::new_from_file($Xo[IMAGE]);
  if(!$i) $i=null;

  /*if($Xo[TYPE]=='checkbox')
  {
   $button=new GtkToggleToolButton($i,$Xo[LABEL]);
   $button->set_active(GulOptions(array('true'),array(1,0),$Xo[CHECKED]));
  }
  if($Xo[TYPE]=='radio')
  {
   $button=new GtkRadioToolButton($i,$Xo[LABEL]);
   if(!$Xlast[radiotoolgroup][$Xo[NAME]]) $Xlast[radiotoolgroup][$Xo[NAME]]=$button;
   else $button->set_group($Xlast[radiotoolgroup][$Xo[NAME]]);
   $button->set_active(GulOptions(array('true'),array(1,0),$Xo[CHECKED]));
  }
  */

  /*
  if($Xo[TYPE]=='menu') $button=new GtkMenuToolButton(GtkImage::new_from_stock(null,Gtk::ICON_SIZE_SMALL_TOOLBAR),$Xo[LABEL]);
  else $button=new GtkToolButton($i,$Xo[LABEL]);
  */
  $button=new GtkToolButton($i,$Xo[LABEL]);
  GulStyle($Xlast[$Yn][STYLE],$button->child,$button->child,$button->child->child);
 }

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $button->show_all();

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($button,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($button,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xwidgets[$Yn-1]->insert($button,-1);

 $Xwidgets[$Yn]=$button;
 if($Xo[ID]) $Guls[$Xo[ID]]=$button;

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($button,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($button,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $button->set_sensitive($Xo[DISABLED]);

 GulEvent($button,array('clicked','clicked'),array($Xo[ONCOMMAND],$Xo[ONCLICK]));
}



function GulToolBarSeparator()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $sep=new GtkSeparatorToolItem();
 $Xwidgets[$Yn-1]->insert($sep,-1);

 $Xwidgets[$Yn]=$sep;
 if($Xo[ID]) $Guls[$Xo[ID]]=$sep;

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $sep->show_all();
}







function GulTree()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;
 if(!$Xo[FLEX]) $Xo[FLEX]=0;

 $treeview = new GtkTreeView();
 $treeview->set_headers_visible(1);
 $selection=$treeview->get_selection();
 if(strtolower($Xo[SELTYPE])=='multiple') $selection->set_mode(Gtk::SELECTION_MULTIPLE);

 $Xlast[ctreeColNumber]=0;

 $Xwidgets[$Yn]=$treeview;
 if($Xo[ID]) $Guls[$Xo[ID]]=$treeview;

 $scrwnd = new GtkScrolledWindow();
 $scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
 $scrwnd->add($treeview);

 GulStyle('width:200;'.$Xlast[$Yn][STYLE],$scrwnd);
 GulStyle($Xlast[$Yn][STYLE],$treeview);

 if(isset($Xo[TOOLTIPTEXT])) GulTooltip($treeview,$Xo[TOOLTIPTEXT]);
 if(isset($Xo[TOOLTIP])) GulTooltip($treeview,$Xlast[tooltip][$Xo[TOOLTIP]]);

 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 GulPack($scrwnd,$Xo[FLEX]);

 $Xo[DISABLED]=GulOptions(array('true'),array(0,1),$Xo[DISABLED]);
 $treeview->set_sensitive($Xo[DISABLED]);

 $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
 if(!$Xo[HIDDEN]) $scrwnd->show_all();

 GulEvent($selection,array('changed'),array($Xo[ONSELECT]));
}



function GulTreeCol()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;

 $cell_renderer=new GtkCellRendererText();
 $col=new GtkTreeViewColumn('',$cell_renderer,'text',$Xlast[ctreeColNumber]);
 $col->set_resizable(GulOptions(array(1),array(1,0),$Xo[FLEX]));
 $col->set_clickable(1);
 $Xwidgets[$Yn-1]->append_column($col);
 $Xlast[ctreeColNumber]++;


 // box
 if(!$Xo[FLEX]) $Xo[FLEX]=0;
 $Xlast[$Yn][DIR]=GulOptions(array('reverse'),array(0,1),$Xo[DIR]);
 $Xo[ORIENT]=GulOptions(array('vertical','horizontal'),array(0,1,1),$Xo[ORIENT]);
 $Xo[EQUALSIZE]=GulOptions(array('always'),array(1,0),$Xo[EQUALSIZE]);

 if($Xo[ORIENT])
 {
  $Xo[ALIGN]=strtolower($Xo[ALIGN]);
  if($Xo[ALIGN]=='start'||$Xo[ALIGN]=='center'||$Xo[ALIGN]=='end') $flex2=0;
  else $flex2=1;
  if($Xo[ALIGN]=='left'||$Xo[ALIGN]=='right') $flex=0;
  else $flex=1;

  $Xo[VALIGN]=GulOptions(array('start','center','end'),array(0,0.5,1,0),$Xo[ALIGN]);
  $Xo[ALIGN]=GulOptions(array('left','right'),array(0,1,0),$Xo[ALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkHBox();
 }
 else
 {
  if($Xo[ALIGN]) $flex=0; else $flex=1;
  if($Xo[VALIGN]) $flex2=0; else $flex2=1;
  $Xo[ALIGN]=GulOptions(array('start','center','end','left','right'),array(0,0.5,1,0,1,0),$Xo[ALIGN]);
  $Xo[VALIGN]=GulOptions(array('top','middle','bottom'),array(0,0.5,1,0),$Xo[VALIGN]);
  $align = new GtkAlignment($Xo[ALIGN],$Xo[VALIGN],$flex,$flex2);
  $box = new GtkVBox();
 }
 //$box->set_spacing(5);

 $ebox=new GtkEventBox();
 if(isset($Xo[CONTEXT])) $ebox->connect('button-press-event','GulShowPopup',$Xo[CONTEXT]);

 $Xo[OVERFLOW]=GulOptions(array('auto','scroll'),array(1,2,0),$Xo[OVERFLOW]);
 if($Xo[OVERFLOW])
 {
  $scrwnd=new GtkScrolledWindow();
  if($Xo[OVERFLOW]==1) $scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  if($Xo[OVERFLOW]==2) $scrwnd->set_policy(Gtk::POLICY_ALWAYS,Gtk::POLICY_ALWAYS);

  $scrwnd->add_with_viewport($ebox);
  $scrwnd->child->set_shadow_type(0);
  $ebox->add($align);
  $align->add($box);

  GulStyle($Xlast[$Yn][STYLE],$scrwnd,$ebox,'','','',$align,$box);
  $col->set_widget($scrwnd);

  $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
  if(!$Xo[HIDDEN]) $scrwnd->show_all();
 }
 else
 {
  $ebox->add($align);
  $align->add($box);

  GulStyle($Xlast[$Yn][STYLE],$box,$ebox,'','','',$align);
  $col->set_widget($ebox);

  $Xo[HIDDEN]=GulOptions(array('true','hidden'),array(1,1,0),$Xo[HIDDEN]);
  if(!$Xo[HIDDEN]) $ebox->show_all();
 }

 $box->set_homogeneous($Xo[EQUALSIZE]);
 $Xwidgets[$Yn]=$box;
 if($Xo[ID]) $Guls[$Xo[ID]]=$box;

 GulEvent($ebox,array('enter_notify_event','leave_notify_event','button-press-event'),array($Xo[ONMOUSEOVER],$Xo[ONMOUSEOUT],$Xo[ONCLICK]));
}





function GulTreeGoCol()
{
 global $Xo,$Yn,$Xwidgets,$Guls,$Xlast;
 
  $s='$store = new GtkTreeStore(';
  for($i=0; $i<$Xlast[ctreeColNumber]; $i++)
  {
   if($i) $s.=',';
   $s.='Gtk::TYPE_STRING';
  }
  $s.=');';
  eval($s);

 $Xwidgets[$Yn]->set_model($store);

 $Xlast[Tree]=$Xwidgets[$Yn];
 $Xlast[TreeStore]=$store;
 $Xlast[Treen][$Yn]=null;
}








?>
